package com.ag.dao;

import java.util.Date;
import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ag.bean.TbPlan;

/**
 * A data access object (DAO) providing persistence and search support for
 * TbPlan entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.ag.bean.TbPlan
 * @author MyEclipse Persistence Tools
 */

public class TbPlanDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(TbPlanDAO.class);
	// property constants
	public static final String _PNAME = "PName";
	public static final String _PSUMMARY = "PSummary";
	public static final String _PUNIT = "PUnit";
	public static final String _PCONTRACTOR = "PContractor";
	public static final String _PVERSION = "PVersion";
	public static final String _POPINION = "POpinion";
	public static final String A = "a";
	public static final String B = "b";
	public static final String C = "c";

	protected void initDao() {
		// do nothing
	}

	public void save(TbPlan transientInstance) {
		log.debug("saving TbPlan instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(TbPlan persistentInstance) {
		log.debug("deleting TbPlan instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public TbPlan findById(java.lang.String id) {
		log.debug("getting TbPlan instance with id: " + id);
		try {
			TbPlan instance = (TbPlan) getHibernateTemplate().get(
					"com.ag.bean.TbPlan", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List<TbPlan> findByExample(TbPlan instance) {
		log.debug("finding TbPlan instance by example");
		try {
			List<TbPlan> results = (List<TbPlan>) getHibernateTemplate()
					.findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TbPlan instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from TbPlan as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List<TbPlan> findByPName(Object PName) {
		return findByProperty(_PNAME, PName);
	}

	public List<TbPlan> findByPSummary(Object PSummary) {
		return findByProperty(_PSUMMARY, PSummary);
	}

	public List<TbPlan> findByPUnit(Object PUnit) {
		return findByProperty(_PUNIT, PUnit);
	}

	public List<TbPlan> findByPContractor(Object PContractor) {
		return findByProperty(_PCONTRACTOR, PContractor);
	}

	public List<TbPlan> findByPVersion(Object PVersion) {
		return findByProperty(_PVERSION, PVersion);
	}

	public List<TbPlan> findByPOpinion(Object POpinion) {
		return findByProperty(_POPINION, POpinion);
	}

	public List<TbPlan> findByA(Object a) {
		return findByProperty(A, a);
	}

	public List<TbPlan> findByB(Object b) {
		return findByProperty(B, b);
	}

	public List<TbPlan> findByC(Object c) {
		return findByProperty(C, c);
	}

	public List findAll() {
		log.debug("finding all TbPlan instances");
		try {
			String queryString = "from TbPlan";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public TbPlan merge(TbPlan detachedInstance) {
		log.debug("merging TbPlan instance");
		try {
			TbPlan result = (TbPlan) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(TbPlan instance) {
		log.debug("attaching dirty TbPlan instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(TbPlan instance) {
		log.debug("attaching clean TbPlan instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static TbPlanDAO getFromApplicationContext(ApplicationContext ctx) {
		return (TbPlanDAO) ctx.getBean("TbPlanDAO");
	}
}